# 设置变量
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# API相关配置
import hashlib
import requests
import datetime
import json

# 设置参数
QR_CODE = "10043901"
MERCHANT_ID = "1424798487462144"
DATE = "20250509"  # 获取当前日期，格式为YYYYMMDD
API_URL = "https://apibk.5ug.top/app/merchant/deviceInfo/scanUser"

# 生成签名（DATE+MERCHANT_ID+QR_CODE的MD5加密）
SIGN_STR = f"{DATE}{MERCHANT_ID}{QR_CODE}"
print(SIGN_STR)
# 使用MD5而不是base64
SIGN = hashlib.md5(SIGN_STR.encode('utf-8')).hexdigest()
print(SIGN)
# 构造JSON请求体
params = {
    "qrCode": QR_CODE,
    "date": DATE,
    "merchantId": MERCHANT_ID,
    "sign": SIGN
}

# 打印请求参数
print("请求参数:", params)

# 发送请求
headers = {"Content-Type": "application/json"}
response = requests.post(API_URL, json=params, headers=headers)

# 打印响应结果
print("\n响应状态码:", response.status_code)
print("响应内容:", response.text)

try:
    result = response.json()
    print("\n解析后的JSON:", json.dumps(result, indent=2, ensure_ascii=False))
except:
    print("响应不是有效的JSON格式")
